﻿using AbpApplication.Expand;
using AbpApplication.InPut;
using AbpToDomain.EntityInfo;
using AbpToDomain.View;
using LinqSharp;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;
using Volo.Abp.Domain.Repositories;

namespace AbpApplication.AppServices
{
    public class ViewService : ApplicationService, IViewService
    {

        private readonly QueryDynamic_View_Materials queryDynamic_View_Materials;
        private readonly IRepository<View_User> View_user_res;
        public ViewService(QueryDynamic_View_Materials queryDynamic_View_Materials, IRepository<View_User> view_user_res)
        {
            this.queryDynamic_View_Materials = queryDynamic_View_Materials;
            View_user_res = view_user_res;
        }

        public async Task<ApiResponsePage> GetList_View_Materials(InPut_ViewService Input)
        {
            try
            {
                var view_materials = queryDynamic_View_Materials.QueryDynameic(Input.BoxCode);
                long count = view_materials.LongCount();//计算出了总条数
                long pageCount = (long)Math.Ceiling(count * 1.0 / Input.PageSize);
                view_materials = view_materials.SelectPage(Input.PageIndex, Input.PageSize).ToList();
                return new ApiResponsePage("获取成功", true, view_materials, count, pageCount);
            }
            catch (Exception ex)
            {
                Logger.LogWarning($"GetList_View_Materials-{Input}" + ex.Message);
                return new ApiResponsePage("内部服务器错误", false, null, null, null);
            }
     
        }

        public async Task<ApiResponse> GetList_View_User()
        {
            try
            {
                List<View_User> view_Users = await View_user_res.GetListAsync();
                return new ApiResponse("获取成功", true, view_Users);
            }
            catch(Exception ex)
            {
                Logger.LogWarning($"GetList_View_User" + ex.Message);
                return new ApiResponse("内部服务器错误", false, null);
            }
      
        }
    }
}
